<template>
  <div>
    <h2 align="center">添加理财信息</h2>
    <table class="table table-bordered">
      <tr>
        <td>项目名称</td>
        <td>
          <input type="text" v-model="addData.T_Name" >
        </td>
      </tr>

      <tr>
        <td>年收益</td>
        <td>
          <input type="text" v-model="addData.T_Year" >
        </td>
      </tr>

      <tr>
        <td>月收益</td>
        <td>
          <input type="text" v-model="addData.T_Month" >
        </td>
      </tr>

      <tr>
        <td>最低金额</td>
        <td>
          <input type="text" v-model="addData.T_MinMoney" >
        </td>
      </tr>

      <tr>
        <td>风险等级</td>
        <td>
          <input type="radio" name="T_Inves" value="低" v-model="addData.T_Inves" checked >低
          <input type="radio" name="T_Inves" value="中" v-model="addData.T_Inves" >中
          <input type="radio" name="T_Inves" value="高" v-model="addData.T_Inves" >高
        </td>
      </tr>

      <tr>
        <td>利息</td>
        <td>
          <select v-model="addData.G_Id">
            <option value="0">请选择</option>
            <option v-for="item in list" :key="item.G_Id" :value="item.G_Id">{{item.G_Name}}</option>
          </select>
        </td>
      </tr>

      <tr>
        <td></td>
        <td>
          <input type="button" value="添加" @click="AddInfo" class="btn btn-primary">
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">

import {reactive,toRefs,onMounted } from 'vue'

import axios from 'axios';

import {useRouter,useRoute} from 'vue-router'

let router = useRouter()

//数据
let data:any = reactive({
  list:[],
  addData:{
    T_Name:'',
    T_Year:'',
    T_Month:'',
    T_MinMoney:'',
    T_Number:0,
    T_Inves:'低',
    G_Id:0
  }
})

//解构
let {list,addData} = toRefs(data)

onMounted(()=>{
  BindGMoney()
})

//绑定利息表
const BindGMoney =()=>{
  //利息表
  axios({
    url:'/api/TManage/BindMoney',
    method:'get'
  }).then((res)=>{
    list.value = res.data.data
  })
}

//添加
const AddInfo = ()=>{
  //非空判断
  if(addData.value.T_Name==""){
    return alert('项目名称不能为空')
  }
  if(addData.value.T_Year==""){
    return alert('年收益不能为空')
  }
  if(addData.value.T_Month==""){
    return alert('月收益不能为空')
  }
  if(addData.value.T_MinMoney==""){
    return alert('最低金额不能为空')
  }
  //最低金额为10000
  if(addData.value.T_MinMoney<10000){
    return alert('最低金额不能小于10000')
  }
  if(addData.value.G_Id==0){
    return alert('请选择利息')
  }
  //添加
  axios({
    url:'/api/TManage/AddManage',
    method:'post',
    data:addData.value
  }).then((res)=>{
    if(res.data.data==-1){
      return alert('该理财项目已存在')
    }else if(res.data.data>0){
      alert('添加成功')
      router.push('/showManage')
    }else{
      alert('添加失败')
    }
  })
}

</script>

<style scoped>

</style>